<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<!--<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
-->	
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">

		<script type="text/javascript" src="./libs/spark-md5-3.0.0.min.js"></script>
		<script type="text/javascript" src="./libs/crypto-js.js"></script>
		<script type="text/javascript" src="./libs/base64.min.js"></script>
		<script type="text/javascript" src="./libs/ufile-token.js"></script>

		<style>
			input.picInput {
				display: none;
			}
			
			img.picShow {
				width: 80px;
				height: 80px;
			}
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>游戏用户</a>
						</li>
						<li class="active">活动管理</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							活动列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">名称</button>
											</div>
											<input type="text" class="form-control" id="name">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">是否首页显示</button>
											</div>
											<select type="text" class="form-control" id="is_home">
												<option value="">全部</option>
												<option value="0">不是</option>
												<option value="1">是</option>
											</select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">时间范围</button>
											</div>
											<!-- /btn-group -->
											<input type="text" class="form-control" id="select_time">
											<div class="input-group-addon clearBtns" onclick="clearRangeTime(this)">x</div>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
									</div>
									<div class="col-xs-12">

										<div class="fixed-table-toolbar margin">
											<div class="bs-bars pull-left">
												<div class="hidden-xs" id="managerTableToolbar" role="group">
													<!--新增、冻结、解冻、拉黑、移除黑名单。充值金币-->
													<button type="button" class="btn btn-primary " onclick="addActivity()" id=""><i class="fa fa-plus"></i>&nbsp;新增</button>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>ID</th>
												<th>游戏名称</th>
												<th>游戏logo</th>
												<th>跳转URL</th>
												<th>首页图片</th>
												<th>是否在首页显示</th>
												<th>添加时间</th>
												<th>操作</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		<div class="modal fade parents in" id="addActivityModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
						<h4 class="modal-title">添加活动</h4> </div>
					<div class="modal-body">
						<div class="row">
							<label class="margin-bottom-none col-xs-12">游戏id<select class="form-control game_id" name="game_id"></select></label>
							<label class="margin-bottom-none col-xs-12">名称<input type="text" class="form-control" name="name"></label>
							<label class="margin-bottom-none col-xs-12">url<input type="text" class="form-control" name="url"></label>
							<div class="margin-bottom-none col-xs-12">
								<div>图片</div>
								<label style="display: inline-block;">
									<input type="file" class="form-control onePic picInput" name="add_img"/>
									<img src="img/add.png" class="picShow" alt="" name="add_img"/>
								</label>
							</div>
						</div>
					</div>
					<div class="modal-footer"><button type="button" class="btn btn-primary save" onclick="addSave()">确定</button></div>
				</div>
			</div>
		</div>
		<div class="modal fade parents in" id="editActivityModal">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
						<h4 class="modal-title">修改活动</h4> </div>
					<div class="modal-body">
						<div class="row">
							<input type="hidden" name="id" />
							<label class="margin-bottom-none col-xs-12">游戏id<select type="text" class="form-control game_id" name="game_id"></select></label>
							<label class="margin-bottom-none col-xs-12">名称<input type="text" class="form-control" name="name"></label>
							<label class="margin-bottom-none col-xs-12">url<input type="text" class="form-control" name="url"></label>
							<div class="margin-bottom-none col-xs-12">
								<div>图片</div>
								<label style="display: inline-block;">
									<input type="file" class="form-control onePic picInput" name="edit_img"/>
									<img src="img/add.png" class="picShow" alt="" name="edit_img"/>
								</label>
							</div>
							<div class="col-xs-12" style="line-height: 2;">首页展示
								<div class="col-xs-12" style="padding: 0;">
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="edit_is_home" value="1" style="margin:0 5px 0 0;"/> 是
									</label>
									<label class="margin-r-5" style="font-weight: normal;">
										<input type="radio" name="edit_is_home" value="0" style="margin:0 5px 0 0;"/> 否
									</label>
								</div>
							</div>
						</div>
					</div>
					<div class="modal-footer"><button type="button" class="btn btn-primary save" onclick="editSave()">确定</button></div>
				</div>
			</div>
		</div>
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>

		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<script type="text/javascript">
			var ufile = new UCloudUFile(bucketName, bucketUrl, tokenPublicKey, tokenPrivateKey, tokenServerUrl, prefix);

			$.ajax({
				'type': 'post',
				'url': url + "Back_GameList",
				"headers": {
					"auth-token": localStorage.getItem("wallet_token")
				},
				'contentType': "application/x-www-form-urlencoded",
				data: {
					data: JSON.stringify({
						page_num: 1,
					})
				},
				success: function(res) {
					if(res.status == 1000||res.status == 102) {
						ToLogin(res)
						return false;
					} else if(res.status != 1) {
						alert(res.error);
						return false;
					}
					$.each(res.data.data_list,function(index,item){
						if(index == 0){
							$(".game_id").append('<option value="">全部</option>')
						}
						$(".game_id").append('<option value="'+item.id+'">'+item.name+'</option>')
					})
					
				}
			})

			$('#select_time').daterangepicker({
				timePicker: true,
				timePicker24Hour: true,
				autoUpdateInput: false,
				locale: {
					format: "YYYY-MM-DD HH:mm"
				}
			})

			var table = $('#example').DataTable({
				'ordering': false,
				'lengthChange': false,
				'searching': false,
				'info': true,
				"processing": true,
				"serverSide": true,
				'scrollX':true,
				"ajax": {
					"type": 'post',
					"url": url + "Back_GameActivityList",
					'contentType': "application/x-www-form-urlencoded",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					"data": function(d) {
						var dataType = {
							name: {
								type: 'string',
								value: $("#name").val()
							},
							is_home: {
								type: 'string',
								value: $("#is_home").val()
							},
							start_time: {
								type: 'time',
								value: $("#select_time").val().substring(0, 16)
							},
							end_time: {
								type: 'time',
								value: $("#select_time").val().substring(19, 35)
							}
						}
						var Json = renderData(dataType);
						Json.page_num = d.start / 10 + 1;
						var data = {};
						data.data = JSON.stringify(Json);
						return data;
					},
					"dataFilter": function(data) {
						var datajson = eval('(' + data + ')');
						if(datajson.status == 1000||datajson.status == 102) {
							ToLogin(datajson)
							return false;
						} else if(datajson.status != 1) {
							alert(datajson.error);
							return false;
						}
						var json = {};
						if(datajson.data == null) {
							json.recordsTotal = 0;
							json.recordsFiltered = 0;
							json.data = [];
							return JSON.stringify(json);
						} else {
							json.recordsTotal = datajson.data.total;
							json.recordsFiltered = datajson.data.total;
							json.data = datajson.data.data_list;
							return JSON.stringify(json);
						}
					}
				},
				"columns": [{
						data: 'id'
					},
					{
						data: 'name'
					},
					{
						data: null,
						render: function(data) {
							return '<img class="tablePic" src = "' + hasHttp(data.game_logo) + '">';
						}
					},
					{
						data: 'url'
					},
					{
						data: null,
						render: function(data) {
							return '<img class="tablePic" src = "' + hasHttp(data.img) + '">';
						}
					},
					{
						data: null,
						render: function(data) {
							var is_home_list = {
								0: '否',
								1: '是'
							}
							return is_home_list[data.is_home];
						}
					},
					{
						data: 'add_time'
					},
					{
						data: null,
						render: function(data) {
							return "<input type='hidden' value='" + JSON.stringify(data) + "'><button type='button' class='btn btn-primary button-margin' onclick='editAtivity(this)' ><i class='fa fa-pencil'></i>&nbsp;修改</button><button type='button' class='btn btn-danger button-margin' onclick='delAtivity(this)'><i class='fa fa-trash-o'></i>&nbsp;删除</button>"
						}
					}

				]
			})
		</script>
		<script type="text/javascript">
			// 添加
			function addSave() {
				$.ajax({
					'type': 'post',
					'url': url + "Back_GameActivityAdd",
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					'contentType': "application/x-www-form-urlencoded",
					data: {
						data: JSON.stringify({
							game_id: Number($("#addActivityModal [name=game_id]").val()),
							name: $("#addActivityModal [name=name]").val(),
							img: strSplitUrl($("#addActivityModal img[name=add_img]").attr("src")),
							url: $("#addActivityModal [name=url]").val(),
						})
					},
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#addActivityModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function addActivity() {
				$("#addActivityModal").modal('show');
				$("#addActivityModal").find('input').val("");
			}

			function editAtivity(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				$("#editActivityModal").modal('show');
				$.each(data, function(index, item) {
					if(index == "is_home") {
						$("#editActivityModal [name=edit_is_home][value=" + item + "]").prop("checked", true);
					} else if(index == "img") {
						$("#editActivityModal [name=edit_img]").attr('src', hasHttp(item));
					} else {
						$("#editActivityModal [name=" + index + "]").val(item);
					}

				})
			}
			// 修改
			function editSave() {
				$.ajax({
					'type': 'post',
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					'contentType': "application/x-www-form-urlencoded",
					url: url + "Back_GameActivityUpdate",
					data: {
						data: JSON.stringify({ //昵称
							game_id: $("#editActivityModal [name=game_id]").val(),
							name: $("#editActivityModal [name=name]").val(),
							img: strSplitUrl($("#editActivityModal img[name=edit_img]").attr("src")),
							url: $("#editActivityModal [name=url]").val(),
							is_home: Number($("#editActivityModal [name=edit_is_home]:checked").val()),
							status: 1,
							id: $("#editActivityModal [name=id]").val(),
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#editActivityModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function delSave() {
				$.ajax({
					'type': 'post',
					"headers": {
						"auth-token": localStorage.getItem("wallet_token")
					},
					'contentType': "application/x-www-form-urlencoded",
					url: url + "Back_GameActivityUpdate",
					data: {
						data: JSON.stringify({ //昵称
							status: 2,
							id: $("#delAtivityModal [name=id]").val()
						})
					},
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#delAtivityModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function delAtivity(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "delAtivity",
					title: "活动删除",
					arg: {
						id: data.id,
						name: data.name
					}
				};
				deleteModal(deleteJson, 'delSave');
			}

			$(".onePic").change(function() {
				var date = new Date()
				var fileRename = date.valueOf()+Math.ceil(Math.random()*100);;
				var file = $(this)[0].files[0];
				var that = $(this)
				var data = {
					file: file,
					fileRename: fileRename
				};
				var errorCallBack = function(res) {
					console.log(res)
				};
				var successCallBack = function(res) {
					console.log(res)
					console.log(that)
					that.siblings('img').attr("src", bucketUrl + fileRename)
				};
				var progressCallBack = function(res) {};

				ufile.uploadFile(data, successCallBack, errorCallBack, progressCallBack);
			})
		</script>
	</body>

</html>